home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-21 | 6.3 KB | 320 lines | [TEXT/PJMM] |
- PROGRAM CreateSectionDir;
-
- USES
- HFS, StackStuff;
-
-
- CONST
-
- line1 = 'Library Report - ';
- line2 = 'Last Updated - ';
-
- title1 = 'ID# Program Name Acc. T Uploaded By Date Blocks';
- title2 = '---- --------------------- ---- - ------------------- ---------- ------';
-
-
-
-
- VAR
- currentID : integer;
- outFile : text;
-
- dateStr, acctStr, typeStr, uploadedByStr : str255;
-
- {================================================================================}
-
- {==================================================================================}
-
- PROCEDURE DisplayOSErr (theOSErr : integer;
- theStr : str255);
- BEGIN
- IF theOSErr <> noErr THEN
- writeln('OSErr: ', theOSErr, ' "', theStr, '"');
- END;
-
- PROCEDURE FailOSErr (theOSErr : integer);
- BEGIN
- IF theOSErr <> noErr THEN
- writeln('An error, #', theOSErr, ' occurred.');
- END;
-
-
-
- FUNCTION GetKthIndexedFileInDirectory (k : integer;
- vRefNum : integer;
- dirID : integer;
- VAR paramBlock : CInfoPBRec) : boolean;
-
- VAR
- theOSErr : integer;
-
- BEGIN
-
- paramBlock.ioVRefNum := vRefNum;
- paramBlock.ioDirID := dirID;
- paramBlock.ioFDirIndex := k;
-
- theOSErr := PBGetCatInfo(@paramBlock, FALSE);
-
- IF theOSErr = -43 THEN
- GetKthIndexedFileInDirectory := false
- ELSE IF theOSErr <> noErr THEN
- BEGIN
- writeln('GetKthIndexedFileInDirectory: osErr = ', theOSErr);
- GetKthIndexedFileInDirectory := false
- END
- ELSE
- GetKthIndexedFileInDirectory := true;
-
- END;
-
-
-
- PROCEDURE DisplayParamBlockInfo (paramBlock : CInfoPBRec);
- VAR
- fileName : str255;
- size : longint;
- BEGIN
-
- writeln('Writing file #', currentID, ' ', paramBlock.ioNamePtr^);
-
-
- write(outFile, currentID : 4);
- write(outFile, ' ');
-
- fileName := concat(paramBlock.ioNamePtr^, ' ');
- write(outFile, fileName : 20);
- write(outFile, ' ');
-
- write(outFile, acctStr);
- write(outFile, ' ');
-
- write(outFile, typeStr);
- write(outFile, ' ');
-
- write(outFile, uploadedByStr);
- write(outFile, ' ');
-
- write(outFile, dateStr);
- write(outFile, ' ');
-
- size := (paramBlock.ioFlPyLen + paramBlock.ioFlRPyLen) DIV 128 + 1;
- write(outFile, size : 6);
-
- writeln(outFile);
-
-
- writeln(outFile, ' DESC:<Description>');
-
- writeln(outFile, ' KEY:<Key>');
-
- END;
-
-
-
- PROCEDURE WriteSubdirectoryToSectionDirFile (volToCatalog : integer;
- DoCatalog : boolean);
-
- VAR
- paramBlock : CInfoPBRec;
- theOSErr : integer;
-
- vRefNum : integer;
- dirID : integer;
- fileIndex : integer;
-
- volName : str255;
- theNameStr : str255;
-
- subdirectories : StackType;
- BEGIN
-
- FailOSErr(SetVol(NIL, volToCatalog));
- FailOSErr(GetVol(@theNameStr, vRefNum));
- FailOSErr(SetVol(@theNameStr, 0));
- FailOSErr(GetVol(NIL, vRefNum));
-
- writeln('Vol to catalog - vRef:', vRefNum, ' dirID:', volToCatalog);
-
- dirID := 0;
-
- StackInitialize(subdirectories);
- StackPush(subDirectories, dirID);
- theNameStr := 'Keith';
-
- paramBlock.ioNamePtr := @theNameStr;
-
- WHILE StackEmpty(subDirectories) = FALSE DO
- BEGIN
- dirID := StackPop(subDirectories);
- fileIndex := 1;
-
- writeln('Directory ID ', dirID, ' stack size ', subDirectories.size);
-
- WHILE GetKthIndexedFileInDirectory(fileIndex, vRefNum, dirID, paramBlock) DO
- BEGIN
-
- IF BitTst(@paramBlock.ioFlAttrib, 3) = TRUE THEN
- BEGIN
- StackPush(subDirectories, paramBlock.ioDirID);
- writeln('PUSHING ', paramBlock.ioDirID, ' name ', paramBlock.ioNamePtr^);
- END
- ELSE IF DoCatalog THEN
- BEGIN
- currentID := currentID - 1;
- DisplayParamBlockInfo(paramBlock);
- END
- ELSE
- BEGIN
- currentID := currentID + 1;
- writeln('COUNTING #', currentID, ' "', paramBlock.ioNamePtr^, '"');
- END;
- fileIndex := fileIndex + 1;
-
- END;
-
- END; {of while StackEmpty() = FALSE }
-
- END;
-
- {=================================================================}
-
- PROCEDURE OpenOutputFile (fileName : str255;
- vRefNum : integer);
- CONST
- LibraryReportID = 128;
- lastUploadedID = 129;
- acctStrID = 130;
- typeStrID = 131;
- uploadedByID = 132;
- dateStrID = 133;
-
- VAR
- currentVRefNum : integer;
-
- strH : StringHandle;
-
- BEGIN
-
- FailOSErr(GetVol(NIL, currentVRefNum));
-
- FailOSErr(SetVol(NIL, vRefNum));
-
- rewrite(outFile, fileName);
-
- strH := GetString(LibraryReportID);
- writeln(outfile, line1, ' ', strH^^);
- writeln(line1, ' ', strH^^);
- DisposHandle(handle(strH));
-
- strH := GetString(lastUploadedID);
- writeln(outfile, line2, ' ', strH^^);
- writeln(line2, ' ', strH^^);
- DisposHandle(handle(strH));
-
- writeln(outfile);
-
- writeln(outfile, title1);
- writeln(title1);
- writeln(outfile, title2);
- writeln(title2);
-
- FailOSErr(SetVol(NIL, currentVRefNum));
-
- strH := GetString(acctStrID);
- acctStr := strH^^;
- DisposHandle(handle(strH));
-
- strH := GetString(typeStrID);
- typeStr := strH^^;
- DisposHandle(handle(strH));
-
- strH := GetString(uploadedByID);
- uploadedByStr := copy(concat(strH^^, ' '), 1, 19);
- DisposHandle(handle(strH));
-
- strH := GetString(dateStrID);
- dateStr := strH^^;
- DisposHandle(handle(strH));
-
- END;
-
- {=================================================================}
-
- FUNCTION GetVolumeToCatalog : integer;
- VAR
- topLeft : Point;
- emptyList : SFTypeList;
- reply : SFReply;
- currentVRefNum : integer;
- volName : str255;
- temp : integer;
- BEGIN
-
- SetPt(topLeft, 40, 40);
- SFGetFile(topLeft, 'Select volume to catalog', NIL, 0, emptyList, NIL, reply);
-
- IF reply.good THEN
- BEGIN
-
- GetVolumeToCatalog := reply.vRefNum;
-
- END
-
- ELSE
-
- GetVolumeToCatalog := -maxint;
-
- END;
-
- {=================================================================}
-
- PROCEDURE CreateOutputFile;
- VAR
- topLeft : Point;
- emptyList : SFTypeList;
- reply : SFReply;
- BEGIN
-
- SetPt(topLeft, 40, 40);
- SFPutFile(topLeft, 'Select file for output', 'Section.Dir', NIL, reply);
-
- IF reply.good THEN
- BEGIN
-
- OpenOutputFile(reply.fName, reply.vRefNum);
-
- END
-
- END;
-
- {=================================================================}
-
-
- VAR
- volToCatalog : integer;
- BEGIN
-
- ShowText;
-
- REPEAT
-
- volToCatalog := GetVolumeToCatalog;
-
- IF volToCatalog <> -maxint THEN
- BEGIN
-
- CreateOutputFile;
-
- currentID := 1;
-
- WriteSubdirectoryToSectionDirFile(volToCatalog, FALSE);
- WriteSubdirectoryToSectionDirFile(volToCatalog, TRUE);
-
- close(outFile);
-
- END;
-
- UNTIL volToCatalog = -maxint;
-
- END.